home *** CD-ROM | disk | FTP | other *** search
- ---- Chapter 5: Accessing the modules -----------------------------------------
-
- This chapter explains the functions that are available in various workspaces
- on the disk to access the facilities provided by the modules.
-
- ---- 5.1 The disk filing functions -------------------------------------------
-
- The disk filing module (DFILE) is built into the IAPL.TOS program. To access
- it you need to use the functions contained in the DFILE workspace. This
- workspace can be loaded or copied in as required. The DFILE functions are
- designed to give easy access to any disk file for reading and writing. The
- functions are as follows:
-
- DFOPEN ~w
- This attempts to open the file named in character vector ~w for reading
- and writing. It returns one for success, otherwise zero. Note that if
- a file is already open, then it is closed first - only one file can be
- open at a time. If the file is successfully opened then it is set up
- ready to be read from the beginning, ie the current position is set
- to the start of the file.
- DFMAKE ~w
- The file named in ~w is deleted (if it exists already) and created
- afresh. It is opened ready for writing (and possible later reading).
- One is returned for success, else zero. Any previously open file is
- closed as for DFOPEN.
- DFCLOSE
- The currently open file (if any) is closed. A value of one is returned.
- This command is in theory never needed, since DFMAKE and DFOPEN both
- automatically close open files, and all open files are closed when
- I-APL terminates. However, it is wise to close any file that has been
- written to, so that any buffered data is written to disk. This is
- especially important if there is likely to be a delay before the next
- file is opened (a delay in which a disk may be removed or exchanged).
- DFSIZE
- This returns the length in bytes of the currently open file, or an empty
- vector (0p0) if there is no file open.
- DFREAD ~w
- ~a DFREAD ~w
- Data is read from the file. ~w is the number of characters to be read.
- If ~a is present then it specifies the position in the file to start
- reading; otherwise the current position is used. The characters read
- are returned from the function as a character vector. If the length of
- this vector is less than the number of characters specified by ~w, then
- the end of the file was reached - as many characters as possible were
- read. If the length is zero, then some other error occurred. In any
- case, the current position is set to the end of the section read in.
- DFWRITE ~w
- ~a DFWRITE ~w
- The data contained in character vector ~w is written to the file, either
- at the current position, or at position ~a, if ~a is specified. The
- number of characters written is returned. If this is less than the
- length of the character vector ~w, then the disk is full. If -1 is
- returned then an error occurred. The current position is moved to the
- end of the written data.
- DFSELECT ~w
- This is used to select a new current directory in the same way as CD
- mentioned earlier. ~w is a character vector containing the directory
- description. One is returned on success, zero on error.
- DFTYPE ~w
- This function returns the type of the scalar/vector/array ~w. The type
- is coded as a number; the following types are possible: 0: boolean,
- 1: character, 4: integer, 6: floating point. (These numbers are the
- lengths of a single element to the nearest byte).
- ~a DFTYPE ~w
- This form of the function converts the array ~w from its current type
- to a new type specified by ~a (using the numbers 0,1,4,6 as above).
- ~w must not be a scalar. The new array is returned by the function.
- The conversion is performed by changing the size of the last axis of
- array; the actual bytes making up the data of the array are unchanged.
- If the requested change is not reversible, then a DOMAIN ERROR is
- produced. Examples of this include: changing an 11-element boolean
- vector to characters (1 DFTYPE 11p0), and changing a three-element
- floating point vector to integers (4 DFTYPE 3p1.1).
- The most common use of DFTYPE is to convert vectors to/from character
- vectors for reading/writing with DFREAD/DFWRITE. In this case, problems
- are only likely to occur in converting boolean vectors. The vector
- should be padded out so that the length is a multiple of 8. The
- following expression will do this for boolean vector X: X,(7-8|(pX)-1)p0
-
- Example use of the DFILE functions:
-
- {example text as in EX1}
-
- ---- 5.2 USEFUL functions ----------------------------------------------------
-
- The USEFUL workspace contains a collection of 'useful' functions that do not
- belong anywhere else. Several of the functions included have already been
- described in the printer driver section. See that section for details on those
- functions. These are the remaining functions:
-
- RGBBACK red green blue
- RGBTEXT red green blue
- These two commands are used to set the colours for the command screen.
- 'red', 'green' and 'blue' are the levels of intensity for the three
- colours, from 0 to 15 (black to full intensity; STE compatible).
- RGBBACK sets the background colour; RGBTEXT sets the colour for the
- text. On a mono system, RGBBACK can be used to switch between black
- on white and white on black: use RGBBACK 15 15 15 or RGBBACK 0 0 0.
- KBRATE delay repeat
- This sets the keyboard repeat rate; 'delay' is the time before a key
- starts to repeat, 'repeat' is the time between repeats. Both times
- are measured in 50ths of a second.
- INKEY
- Wait for a key and return its value as a character scalar. Whilst the
- command is waiting, the COPY cursor works as usual, and so do UNDO and
- the function keys. The other special keys return special characters;
- in the following list a number X represents the character #AV[#IO+X]:
- 1 Left, 2 Right, 3 ToStart, 4 ToEnd, 5 ClearToStart, 6 ClearToEnd,
- 8 Backspace, 13 Return (or Enter), 27 Escape, and 127 Delete. Note
- that Escape does not cause an interrupt; it is returned like any other
- key.
- clear INBUF string
- This command puts keypresses into the keyboard buffer; the keypresses
- are those in character vector 'string'. Any normal characters may be
- used, and in addition those returned by INKEY above. The keypresses
- are inserted at the end of the buffer; ie they become the next
- keypresses to be read. 'clear' is either 0 or 1: if it is one then
- the keyboard buffer is cleared before the keypresses are inserted.
- If the buffer becomes full then no warning is given - the excess keys
- are discarded. You will find that the excess keys are discarded from
- the beginning rather than the end of the string.
- WSDOC string
- This lists all the functions in the workspace whose names begin with
- the characters contained in 'string'. It is possible for 'string' to
- be '', producing a list all functions.
- DDDOC string
- As for WSDOC above, except that only direct definition functions are
- listed.
- DFDOC string
- As for WSDOC, except that only defined functions are listed.
- SUMMARY
- Displays a summary of all the functions in the workspace using their
- comments.
-
- Examples:
-
- {example text as in EX2}
-
- ---- 5.3 Full screen text functions ------------------------------------------
-
- The functions found in the FSCREEN workspace (Full SCREEN text) are used to
- control the text display on the command screen. Text can be written to the
- screen and read off it. The cursor can be moved, and the scrolling output
- window normally used for text display can be restricted to a smaller portion
- of the screen.
-
- Coordinates of character cells are given as two-element vectors of the form:
- (row,column). The top row is row 0, and the left-most column is column 0.
-
- FSLIMITS
- This function returns the size of the full text screen. The result is
- a two-element integer vector containing the number of rows and columns,
- respectively, on the screen.
- ~a FSPUT row column
- Puts a character scalar, vector or 2-dimensional array ~a onto the
- screen with the top-left corner of the block of text at position
- (row,column). Characters that would be off the screen are ignored.
- The function returns 0 0p0.
- FSGET row col nrows ncols
- Gets a block of characters off the screen. The block is 'nrows' rows
- high and 'ncols' columns wide, and its top-left corner is at (row,col).
- The block is returned as a 2-dimensional character array. Any
- characters in the block that are off the screen are returned as spaces
- in the array.
- char FSFILL row col nrows ncols
- Fills an area of the screen with a single character 'char' (a character
- scalar). The area is 'nrows' high and 'ncols' wide, with its top-left
- corner at (row,col). If part of the area is off the screen, then this
- part is ignored. The function returns 0 0p0.
- FSCURSOR ~i0
- The current cursor position is returned as a two-element vector
- containing the row and column positions respectively.
- FSCURSOR row column
- The cursor is moved to the position (row,column), and the previous
- cursor position is returned as a two-element vector. If the new cursor
- position is off the screen then the old position is retained. Note
- that all printing and input occurs at the cursor position, so moving
- the cursor allows this to be controlled.
- FSWINDOW row col nrows ncols
- This sets the size and position of the scrolling window used for normal
- character input and output of text. The window is set to be 'nrows'
- high and 'ncols' wide, with its top-left at (row,col). If the window
- specified is not entirely inside the full screen, then nothing happens.
- Otherwise the new window is set and the cursor is moved to the top-left
- corner of this new window, in other words to (row,col). The window is
- not cleared. The function returns 0 0p0.
-
- Note that changing the position and size of the scrolling window has no effect
- at all on the coordinates used to describe character positions - (0,0) still
- refers to the top-left corner of the full screen, whatever the position of the
- window. Also note that, although quad and quote-quad input and output can't
- change the screen outside the window, the FS functions can still freely use the
- whole screen.
-
- FSWINDOW does not change #PW. This means that I-APL may try to display arrays
- etc. wider than the window in use. Characters printed beyond the right edge
- of the window are ignored. Pressing Escape restores the scrolling window to
- the full screen again.
-
- For programs designed to work on the ST in all modes, a maximum screen size of
- 25 rows and 80 columns must be used, even though 33 rows are available in high
- resolution.
-
- Examples:
-
- {example text as in EX3}
-
- ---- 5.4 The pixel graphics functions ----------------------------------------
-
- The pixel graphics functions are designed to allow the display of points,
- lines, triangles, blocks and text in all three of the ST's screen modes. They
- also have the feature of emulating a screen mode if it is not available; so,
- for example a program that generates a low resolution colour picture will still
- run with a monochrome monitor, only using shades instead of colours.
-
- To use the pixel graphics functions contained in the PGRAPH workspace, the
- PGRAPH module must be installed - ie it should appear in the module list when
- I-APL starts up; see the end of chapter 4 if it is not installed. When this
- module is installed, a separate graphics screen is created. This screen is
- completely independent of the main (command) screen, so pictures can be built
- up bit by bit with direct commands without the display becoming corrupted. To
- switch between the two screens use the UNDO key. The graphics screen is
- automatically displayed when it is cleared (using PGCLS), and the command
- screen is switched to whenever a keyboard input is required.
-
- The graphics functions offer four modes (numbered 0 to 3). Mode 0 is low
- resolution colour with 16 colours available (0-15). The default palette (which
- is set whenever the screen is cleared) has 0,1,14,15 as black, dark grey, light
- grey and white, and colours 2 to 13 as the colours round the colour wheel - see
- the examples. The palette can be redefined after the screen has been cleared
- if necessary.
-
- Mode 1 is medium resolution colour with 4 colours. The default colours for 0
- to 3 are: black, red, yellow and white. Mode 2 is high resolution monochrome
- with 17 shades available, from 0 (the background colour) to 16 (the foreground
- colour). Lines are drawn thickened, as if with points of 2x2 (hi-res) pixels.
- This makes the shades of lines more obvious and also allows the medium res
- colour emulation of the hi-res screen to look almost identical. This mode is
- the best for producing near-identical output on all ST's.
-
- Mode 3 is another high resolution mode, again with 17 shades. However in this
- mode lines are drawn thin on a hi-res screen. This allows finely detailed
- displays to be built up; but note that the medium resolution emulation uses
- thick lines - as if mode 2 was used.
-
- There are three further modes used internally - modes 4, 5 and 6. These are
- the emulation modes. Mode 4 is mode 0 emulated on monochrome, using shades to
- represent the colours. Mode 5 is mode 1 emulated on monochrome, again using
- shades for colours. Mode 6 is the medium resolution emulation of both modes 2
- and 3; 17 shades are used, but the vertical resolution is half that of a
- monochrome screen. These modes do not need to be selected directly - they are
- switched to automatically if the requested mode (0-3) is not available.
-
- The coordinate system used is the same in all the modes. The top-left corner
- of the screen is the origin (0,0); the bottom-right corner is (639,399). In
- other words, the screen is treated as having 640x400 pixels, even if low or
- medium resolution is being used. For the colour modes, these 'logical'
- coordinates (based on 640x400) are converted internally to the actual
- 'physical' coordinates of the screen being used (either 320x200 or 640x200)
- whenever an object is drawn. These conversions are invisible - you can act as
- if you had a 640x400 screen.
-
- All of the drawing commands perform full clipping. In other words, if you try
- to draw an object that is partially or completely off the screen, there will
- be no problem; the command will produce a result as if the 640x400 screen is
- just a window on a much larger drawing surface.
-
- These are the commands; they all return 0 0p0. Note that where a lower-case
- name is included in a command description, it should be replaced by the
- relevant number or list of numbers. If a variable is to be used instead,
- remember to join it to any other numbers or variables forming the vector with
- the comma ('join') operator. If a name is in square brackets, this indicates
- that it is optional. A list of names in curly brackets indicates a sequence
- that can be repeated over and over. See the examples if you are confused.
-
- 'colour' represents a colour or shade; ie a number from 0-15, 0-3 or 0-16
- depending on the mode.
-
- PGCLS mode [ colour ]
- Clear the graphics screen, and set it up for mode 'mode' (0 to 3). The
- screen is cleared to colour (or shade) 'colour', or by default to
- colour 0. The origin is set to be (0,0) and the plot style is reset to
- be dots. The palette is initialised for colour modes. This command
- also displays the graphics screen.
- [ colour ] PGRGB { red green blue }
- Set the colour palette for mode 0 or 1, starting at colour 'colour'
- (defaulting to colour 0). The right argument is taken in chunks of
- three integers. Each group of three integers represents one colour;
- the integers represent the red, green and blue levels (respectively)
- for the colour required, on a scale from 0 to 15 (black to full
- intensity). As many palette colours are set as there are groups of
- three integers on the right.
-
- Note that, whereas on a colour screen PGRGB changes the colours actually
- displayed on the screen, in the monochrome emulation PGRGB has no effect on the
- displayed screen; it only changes the shades used to plot future objects.
-
- The following commands all draw a number of graphic objects; the right argument
- contains the list of coordinates, and the left argument contains the list of
- colours or shades ('clist'). There may be less colours (or shades) listed than
- there are objects to be drawn; in this case the list of colours is repeated
- over and over until all the objects are done. So, for example, if 'clist'
- consisted of a single colour, then this colour would be used for all the
- objects; if a pair of colours were given then these would be used alternately;
- and so on. If no colour list is given then the default colour is used - which
- is 15, 3, 16 or 16, respectively, for modes 0 to 3.
-
- [ clist ] PGPLOT { x y }
- Plot the points listed on the right with the colours on the left.
- Normally the points are plotted as dots, but if a different point
- style has been set up with PGSTYLE then this is used instead.
- [ clist ] PGLINE { x1 y1 x2 y2 }
- Draw the lines listed on the right. Each group of four integers is
- treated as a pair of coordinates; the line is drawn from (x1,y1) to
- (x2,y2).
- [ clist ] PGDRAW { dx dy }
- Draw lines relative; each pair of coordinates is taken to be an offset
- from the last point plotted or drawn to. A line is drawn from the last
- point to this new point. This continues until the list is exhausted.
- So, for example 'PGDRAW 0 10 10 0 0 ~`10 ~`10 0' draws a square with a
- corner on the last point plotted or drawn to.
- [ clist ] PGTRIANG { x1 y1 x2 y2 x3 y3 }
- Draw filled in triangles; each group of six integers on the right is
- taken as three coordinates, which form the three corners of the
- triangle to be drawn.
- [ clist ] PGBLOCK { x1 y1 x2 y2 }
- Draw filled in blocks; (x1,y1) and (x2,y2) are any two opposite
- corners of the (rectangular) block to be drawn.
-
- Note that, although all the right arguments above have been specified to be
- vectors, any shape of array of integers may be used; the array is effectively
- reshaped to a vector and then split up into groups of integers corresponding to
- the objects to be drawn. So, for example, when drawing triangles, it is often
- easier to work with an array of six columns in which each row represents one
- triangle. This array can be passed directly to PGTRIANG for drawing.
-
- PGORIGIN x y
- This sets the graphics origin to position (x,y) relative to the
- top-left corner of the screen. This new origin affects all of the
- following commands. So, if 'PGORIGIN 320 200' is executed, all
- commands would now act as if (0,0) was at the centre of the screen.
- Top-left would be (-320,-200) and bottom-right would be (319,199).
- The only command that is immune to this origin change is PGORIGIN
- itself.
- PGSTYLE { x1 y1 x2 y2 }
- As was mentioned above, you can change the style in which points are
- displayed by PGPLOT to something other than dots. The new shape
- required must be specified as a series of lines whose coordinates are
- given relative to the point to be plotted: (x1,y1) to (x2,y2). A
- maximum of 8 lines may be used. For example, after the command:
- 'PGSTYLE 10 0 ~`10 0 0 10 0 ~`10', all points would be plotted as
- crosses. To set the point style back to dots, pass a null vector on
- the right (ie ~i0).
- x y [ handle [ colour ] ] PGTEXT text
- This command displays text on the screen; 'text' may be a character
- scalar, vector of characters, or two-dimensional array of characters.
- The font used is the system 6x6 font, with APL characters added. It is
- displayed 12 pixels high and 6 pixels wide in all modes except mode 0
- in which it is displayed in 12x12 pixels (using 640x400 coords). The
- reason for not allowing 6x6 in high resolution is that this would make
- the text unreadable when emulated in medium resolution.
- 'x' and 'y' usually give the coordinate of the top-left corner of the
- resulting block of text. However if 'handle' is present, then this
- specifies that (x,y) is the coordinate of a different point on the
- block. 'handle' is a number from 1 to 9 - the meaning is made clear by
- looking at your numeric keypad. The normal value is 7 - specifying the
- top-left corner. If you want to place the block according to its
- centre use 5; if by the mid-point on its bottom edge use 2; and so inter driver JSP =חz =חÕ =ח´ =ט4#Φ D =ם⌠By =ם°?<¯¯?<